Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: send one sample event, response per label set in the configured duration #5298

Merged
merged 71 commits into from
Dec 9, 2024

Conversation

vamsikrishnakandi
Copy link
Contributor

@vamsikrishnakandi vamsikrishnakandi commented Nov 14, 2024

Description

Send one sample event or response per LabelSet to reporting within the configured duration.

  • Generate a hash for each report and store it in badger db.
  • If the hash is already present in the db, do not resend the sample event or response. If the hash is not present, send the sample event/response.
  • The hash stored in the db expires after the configured TTL.

Linear Ticket

Completes OBS-461

Security

  • The code changed/added as part of this pull request won't create any security issues with how the software is being used.

Copy link

codecov bot commented Nov 15, 2024

Codecov Report

Attention: Patch coverage is 71.79487% with 66 lines in your changes missing coverage. Please review.

Project coverage is 74.76%. Comparing base (7ffac25) to head (b040e13).
Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
enterprise/reporting/reporting.go 46.96% 32 Missing and 3 partials ⚠️
...se/reporting/event_sampler/badger_event_sampler.go 76.04% 19 Missing and 4 partials ⚠️
...nterprise/reporting/event_sampler/event_sampler.go 53.84% 5 Missing and 1 partial ⚠️
...ing/event_sampler/in_memory_cache_event_sampler.go 93.10% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #5298      +/-   ##
==========================================
- Coverage   74.78%   74.76%   -0.02%     
==========================================
  Files         433      437       +4     
  Lines       60979    61211     +232     
==========================================
+ Hits        45601    45764     +163     
- Misses      12848    12918      +70     
+ Partials     2530     2529       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@vamsikrishnakandi vamsikrishnakandi marked this pull request as ready for review November 15, 2024 06:19
…tion-on-rudder-server' of https://github.com/rudderlabs/rudder-server into feature/obs-415-support-aggregation-time-as-a-configuration-on-rudder-server
docker-compose.yml Outdated Show resolved Hide resolved
scripts/generate-event Outdated Show resolved Hide resolved
Base automatically changed from feature/obs-415-support-aggregation-time-as-a-configuration-on-rudder-server to master December 6, 2024 09:32
case InMemoryCacheTypeEventSampler:
es, err = NewInMemoryCacheEventSampler(ttl, eventSamplingCardinality)
default:
err = fmt.Errorf("invalid event sampler type: %s", eventSamplerType.Load())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably default to either of the above types and leave a log instead of panicking

Comment on lines 23 to 46
func NewEventSampler(
ttl config.ValueLoader[time.Duration],
eventSamplerType config.ValueLoader[string],
eventSamplingCardinality config.ValueLoader[int],
conf *config.Config,
log logger.Logger,
) (EventSampler, error) {
var es EventSampler
var err error

switch eventSamplerType.Load() {
case BadgerTypeEventSampler:
es, err = NewBadgerEventSampler(BadgerEventSamplerPathName, ttl, conf, log)
case InMemoryCacheTypeEventSampler:
es, err = NewInMemoryCacheEventSampler(ttl, eventSamplingCardinality)
default:
err = fmt.Errorf("invalid event sampler type: %s", eventSamplerType.Load())
}

if err != nil {
return nil, err
}
return es, nil
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
func NewEventSampler(
ttl config.ValueLoader[time.Duration],
eventSamplerType config.ValueLoader[string],
eventSamplingCardinality config.ValueLoader[int],
conf *config.Config,
log logger.Logger,
) (EventSampler, error) {
var es EventSampler
var err error
switch eventSamplerType.Load() {
case BadgerTypeEventSampler:
es, err = NewBadgerEventSampler(BadgerEventSamplerPathName, ttl, conf, log)
case InMemoryCacheTypeEventSampler:
es, err = NewInMemoryCacheEventSampler(ttl, eventSamplingCardinality)
default:
err = fmt.Errorf("invalid event sampler type: %s", eventSamplerType.Load())
}
if err != nil {
return nil, err
}
return es, nil
}
func NewEventSampler(
ttl config.ValueLoader[time.Duration],
eventSamplerType config.ValueLoader[string],
eventSamplingCardinality config.ValueLoader[int],
conf *config.Config,
log logger.Logger,
) (es EventSampler, err error) {
switch eventSamplerType.Load() {
case BadgerTypeEventSampler:
es, err = NewBadgerEventSampler(BadgerEventSamplerPathName, ttl, conf, log)
case InMemoryCacheTypeEventSampler:
es, err = NewInMemoryCacheEventSampler(ttl, eventSamplingCardinality)
default:
err = fmt.Errorf("invalid event sampler type: %s", eventSamplerType.Load())
}
return
}


type InMemoryCacheEventSampler struct {
cache *cachettl.Cache[string, bool]
mu sync.Mutex
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can get rid of the mu from what I can see.. cachettl already takes care of the safety

@@ -0,0 +1,153 @@
package event_sampler
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add tests for both badger samples and in memory samplers

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these are present in event_sampler_test.go


if eventSamplingEnabled.Load() {
var err error
eventSampler, err = event_sampler.NewEventSampler(eventSamplingDuration, eventSamplerType, eventSamplingCardinality, conf, log)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pass ctx into this function and propagate it across

return nil, err
}

go es.gcLoop()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use rruntime.Go instead of go

})
}

func (es *BadgerEventSampler) performGC() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's use the same logic we have for dedup and live events

@cisse21 cisse21 merged commit dc446ee into master Dec 9, 2024
58 checks passed
@cisse21 cisse21 deleted the feat.event-sampling-badger branch December 9, 2024 06:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants